#!/bin/bash

source head.sh

echo '
    <h1>成绩列表</h1>
    <table>
      <tr>
        <th>成绩号</th>
        <th>学生</th>
        <th>考试</th>
        <th>科目</th>
        <th>分数</th>
      </tr>
'
sql="select jx_score.id, jx_stu.name, jx_test.name, jx_subject.name, jx_score.score  from jx_score  join jx_stu on jx_score.stuId=jx_stu.id  join jx_test on jx_score.testId=jx_test.id  join jx_subject on jx_score.subjectId=jx_subject.id;"
stuList=$($mysqllogin "$sql" | grep -v id | sed "s/\t/@/g")
for stu in ${stuList[@]}; do
  # 获取用户ID
  id=$(echo $stu | awk -F "@" '{print $1}')
  stuName=$(echo $stu | awk -F "@" '{print $2}')
  testName=$(echo $stu | awk -F "@" '{print $3}')
  subjectName=$(echo $stu | awk -F "@" '{print $4}')
  score=$(echo $stu | awk -F "@" '{print $5}')
  echo "
        <tr>
          <td>$id</td>
          <td>$stuName</td>
          <td>$testName</td>
          <td>$subjectName</td>
          <td>$score</td>
        </tr>
  "
done

echo '
    </table>
  </div>
</body>
</html>
'

